package api_day05;

public class BinarySortTree {
    Node root;

    public BinarySortTree() {
    }

    public BinarySortTree(Node root) {
        this.root = root;
    }

    public BinarySortTree(int r) {
        this.root = new Node(r);
    }

    private class Node{
        int data;
        Node left,right;

        public Node() {
        }

        public Node(int data) {
            this.data = data;
        }
        public void add(int a){
            if (a <= data){
                if (left == null) left = new Node(a);
                else left.add(a);
            }else {
                if (right == null) right = new Node(a);
                else right.add(a);
            }
        }
    }
    public void add(int a){
        if (root == null){
            root = new Node(a);
        }else {
            root.add(a);
        }
    }
    public void inOrderByRecursion(Node root){
//        该if结构为递归出口
        if (root == null){
            return;
        }
        inOrderByRecursion(root.left);
        System.out.print(root.data+" ");
        inOrderByRecursion(root.right);
    }
}
